## FIXME: this is currently broken for now

from django import template
from paradelib.galleries import Gallery

register = template.Library()

@register.tag
def get_gallery(parser,token):
	"""
		{% get_parade_gallery slug as gallery %}
	"""
	bits = tokens.split_contents()
	if bits[-2].lower() != 'as':
		raise template.TemplateSyntaxError("Missing 'as' from 'get_parade_gallery' template tag.  Format is {% get_parade_gallery slug as gallery %}.")
	return GalleryNode(varname=bits[-1],slug=bits[1])
	
class GalleryNode(template.Node):
	
	def __init__(self,varname,slug):
		self.varname = varname
		self.slug = slug
		
	def render(self,context):
		try:
			gallery = Gallery(self.slug)
		except:
			gallery = None
		context[self.varname] = gallery
		return ''